package sjtu.pirate.report;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import sjtu.pirate.report.Report;
import sjtu.pirate.report.frame.FrameReport;
import sjtu.pirate.analyzer.PirateAnalyzer;

/**
 * @author wilbur.ma@qq.com
 * @date 2011.06.01
 * Use reflection to generate report.
 */
public class ReportFactory {
	public static Report createReport(Class<?> reportClass, String templatesDir, 
			String targetDir, PirateAnalyzer analyzer) {
		Constructor<?> constructor;
		Report report = null;
		try {
			constructor = reportClass.getConstructor(String.class, String.class, PirateAnalyzer.class);
			Object obj = constructor.newInstance(templatesDir, targetDir, analyzer);
			if (obj instanceof Report)
				report = (Report) obj;
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return report;
	}
	
	public static Report createReport(String templatesDir, 	String targetDir, 
			PirateAnalyzer analyzer) {
		return createReport(FrameReport.class, templatesDir, targetDir, analyzer);
	}
}
